package com.ruoyi.ai.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.ai.domain.bo.WxDialogueBo;
import com.ruoyi.ai.domain.vo.WxDialogueVo;
import com.ruoyi.ai.service.IWxDialogueService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.Collections;

/**
 * 微信小程序-对话管理
 *
 * @author ruoyi
 * @date 2024-04-01
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/wx/ma/dialogue")
public class WxMaDialogueController extends BaseController {

    private final IWxDialogueService iWxDialogueService;

    /**
     * 查询对话列表
     */
    @PostMapping("/pageList")
    public TableDataInfo<WxDialogueVo> pageList(@RequestBody PageQuery pageQuery) {
        WxDialogueBo wxDialogueBo = new WxDialogueBo();
        wxDialogueBo.setWxUserId(getUserId());
        wxDialogueBo.setIsShow(true);
        return iWxDialogueService.queryPageList(wxDialogueBo, pageQuery);
    }
    /**
     * 新增对话
     */
    @Log(title = "对话管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Long> add(@RequestBody WxDialogueBo bo) {
        bo.setWxUserId(getUserId());
        Boolean result = iWxDialogueService.insertByBo(bo);
        return R.ok(bo.getDialogueId());
    }

    /**
     * 删除对话
     * 实际上没删除，只是把isShow改成false
     */
    @Log(title = "对话", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{dialogueId}")
    public R<Void> notShow(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long dialogueId) {
        Boolean b = iWxDialogueService.notShow(Collections.singletonList(dialogueId));
        return R.ok();
    }

    //TODO 根据对话id查询聊天列表


}
